package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.TeacherVo;
import com.ruoyi.system.domain.bo.TeacherBo;
import com.ruoyi.system.service.ITeacherService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教师信息
 *
 * @author ruoyi
 * @date 2025-06-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/teacher")
public class TeacherController extends BaseController {

    private final ITeacherService iTeacherService;

    /**
     * 查询教师信息列表
     */
    @SaCheckPermission("system:teacher:list")
    @GetMapping("/list")
    public TableDataInfo<TeacherVo> list(TeacherBo bo, PageQuery pageQuery) {
        return iTeacherService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出教师信息列表
     */
    @SaCheckPermission("system:teacher:export")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TeacherBo bo, HttpServletResponse response) {
        List<TeacherVo> list = iTeacherService.queryList(bo);
        ExcelUtil.exportExcel(list, "教师信息", TeacherVo.class, response);
    }

    /**
     * 获取教师信息详细信息
     *
     * @param teacherId 主键
     */
    @SaCheckPermission("system:teacher:query")
    @GetMapping("/{teacherId}")
    public R<TeacherVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long teacherId) {
        return R.ok(iTeacherService.queryById(teacherId));
    }

    /**
     * 新增教师信息
     */
    @SaCheckPermission("system:teacher:add")
    @Log(title = "教师信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TeacherBo bo) {
        return toAjax(iTeacherService.insertByBo(bo));
    }

    /**
     * 修改教师信息
     */
    @SaCheckPermission("system:teacher:edit")
    @Log(title = "教师信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TeacherBo bo) {
        return toAjax(iTeacherService.updateByBo(bo));
    }

    /**
     * 删除教师信息
     *
     * @param teacherIds 主键串
     */
    @SaCheckPermission("system:teacher:remove")
    @Log(title = "教师信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{teacherIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] teacherIds) {
        return toAjax(iTeacherService.deleteWithValidByIds(Arrays.asList(teacherIds), true));
    }
}
